<?php

function getCate($pid = 0, &$result = array(), $s = 0)
{
    // 分类层级前展示的空格数
    $s = $s + 4;

    $conn = db::getInstance()->connect();

    //获取数据对象
    $sql = "SELECT * FROM `category` where `pid` = $pid";
    $res = $conn->query($sql);
    while ($row = $res->fetch_assoc()) {
        $row['category'] = str_repeat("&nbsp", $s) . '|--' . $row['category'];
        $result[] = $row;
        getCate($row['id'], $result, $s);
    }
    return $result;
}